﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>salary_grantInsert</title>
    <script src="~/lib/axios/dist/axios.js"></script>
    <script src="~/lib/vue/dist/vue.js"></script>
    <script src="~/lib/element-ui/lib/index.js"></script>
    <link href="~/lib/element-ui/lib/theme-chalk/index.css" rel="stylesheet" />
</head>
<body>
    <div id="app">
        <el-container>
            <el-header>
                <el-card class="box-card">
                    <el-col :span="4"> 薪酬发放登记 </el-col>
                </el-card>
            </el-header>
            <el-main>
                <el-card class="box-card">
                    <el-form ref="form" :model="form" :rules="rules" label-width="80px" :inline="true" size="mini">
                        <el-form-item class="_klpo">
                            <template>
                                <el-button type="primary" @@click="submitForm('form')">提交</el-button>
                            </template>
                            <el-button @@click="eas()">返回</el-button>
                        </el-form-item>
                        <el-form-item label="薪酬单编号" prop="oid" label-width="82px">
                            <el-input v-model="oid" style="width: 160px " :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="本机构总人数" prop="total" label-width="96px">
                            <el-input v-model="total" style="width: 160px " :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="基本薪酬总数" prop="salary_standard_sum" label-width="96px">
                            <el-input v-model="form.salary_standard_sum" style="width: 155px" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="实发总额" label-width="68px">
                            <el-input v-model="form.salary_paid_sum" style="width: 175px " :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="登记人" prop="register" label-width="65px">
                            <template>
                                <el-select v-model="form.register" placeholder="请选择登记人" style="width: 191px ">
                                    <el-option v-for="item in listm"
                                               :key="item.u_id"
                                               :label="item.u_true_name"
                                               :value="item.u_true_name">
                                    </el-option>
                                </el-select>
                            </template>
                        </el-form-item>
                        <el-form-item prop="regist_time" label="登记时间" label-width="68px">
                            <el-date-picker style="width: 183px " :disabled="true" type="datetime" placeholder="选择日期" v-model="form.regist_time"></el-date-picker>
                        </el-form-item>
                    </el-form>
                    <el-divider></el-divider>
                    <el-table :data="list" style="width: 100%" border stripe @@cell-mouse-enter="cx">
                        <el-table-column type="index"
                                         label="序号"
                                         width="150px"
                                         align="center">
                        </el-table-column>
                        <el-table-column prop="human_id"
                                         label="档案编号"
                                         align="center">
                        </el-table-column>
                        <el-table-column prop="human_name"
                                         label="姓名"
                                         align="center">
                        </el-table-column>
                        <el-table-column label="薪酬基本明细"
                                         align="center">
                            <template slot-scope="scope">
                                <el-popover trigger="hover" placement="top">
                                    <p align="center" v-for="item in list1">{{ item.item_name }}: {{ item.salary }}</p>
                                    <div slot="reference" class="name-wrapper">
                                        <el-tag size="medium">详细内容</el-tag>
                                    </div>
                                </el-popover>
                            </template>
                        </el-table-column>
                        <el-table-column label="奖励金额" align="center">
                            <template slot-scope="scope">
                                <el-input v-model.number="scope.row.mony1" @@input="gbian(scope.row)" oninput="value=value.replace(/[^\d.]/g,'')"></el-input>
                            </template>
                        </el-table-column>
                        <el-table-column label="销售绩效总额" align="center">
                            <template slot-scope="scope">
                                <el-input v-model.number="scope.row.mony2" @@input="gbian(scope.row)" oninput="value=value.replace(/[^\d.]/g,'')"></el-input>
                            </template>
                        </el-table-column>
                        <el-table-column label="应扣金额" align="center">
                            <template slot-scope="scope">
                                <el-input v-model.number="scope.row.mony3" @@input="gbian(scope.row)" oninput="value=value.replace(/[^\d.]/g,'')"></el-input>
                            </template>
                        </el-table-column>
                        <el-table-column label="实发金额" align="center">
                            <template slot-scope="scope">
                                {{scope.row.sum=scope.row.salary_sum}}
                            </template>
                        </el-table-column>
                    </el-table>
                </el-card>
            </el-main>
        </el-container>
    </div>
    <script type="text/javascript">
        var vm = new Vue({
            el: "#app",
            data: {
                list: [], //三级机构的人力资源
                lists: [],//三级机构未发工资人力资源
                listm: [],//用户
                list1: [],//薪酬详细信息
                oid: '',//随机编号
                total: '',//人数
                form: {
                    type: '',
                    checker: '',
                    regist_time: '',
                    register: '',
                    salary_standard_sum: '',
                    salary_paid_sum: '',
                },
                rules: {
                    register: [
                        { required: true, message: '请选择登记人', trigger: 'change' }
                    ],
                }
            },
            methods: {
                //金额改变事件
                gbian(row) {
                        var num =(row.mony1 == "" || row.mony1 == null ? 0 : parseInt(row.mony1)) +
                        (row.mony2 == "" || row.mony2 == null ? 0 : parseInt(row.mony2)) +
                        (parseInt(row.zje)) -
                        (row.mony3 == "" || row.mony3 == null ? 0 : parseInt(row.mony3));
                    //实发金额
                    row.salary_sum = num;
                    //实发总金额
                    var nume = 0;
                    for (var index in this.list) {
                        nume += this.list[index].salary_sum;
                    }
                    this.form.salary_paid_sum = nume;
                },
                submitForm(formName) {
                    //表单验证
                    this.$refs[formName].validate((valid) => {
                        if (valid) {
                            this.$confirm('此操作将提交薪酬发放信息, 是否提交?', '提示', {
                                confirmButtonText: '确定',
                                cancelButtonText: '取消',
                                type: 'warning'
                            }).then(() => {
                                //薪酬发放添加
                                axios.get('/salary_grant/Insert', {
                                    params: {
                                        salary_grant_id: this.oid,
                                        first_kind_id: this.list[0].first_kind_id,
                                        first_kind_name: this.list[0].first_kind_name,
                                        second_kind_id: this.list[0].second_kind_id,
                                        second_kind_name: this.list[0].second_kind_name,
                                        third_kind_id: this.list[0].third_kind_id,
                                        third_kind_name: this.list[0].third_kind_name,
                                        human_amount: this.total,
                                        salary_standard_sum: this.form.salary_standard_sum,
                                        salary_paid_sum: this.form.salary_paid_sum,
                                        register: this.form.register,
                                        regist_time: this.form.regist_time
                                    }
                                })
                                    .then(res => {
                                        console.info(res);
                                        for (var index in this.list) {
                                            //人力资源状态修改(已发工资)
                                            axios.get('/salary_grant/Upset/', {
                                                params: {
                                                    huf_id: this.list[index].huf_id,
                                                }
                                            })
                                                .then(res => {
                                                    console.info(res);
                                                })
                                                .catch(err => {
                                                    console.info(err);
                                                });
                                              //薪酬发放详细添加
                                            axios.get('/salary_grant/InsertTo', {
                                                params: {
                                                    salary_grant_id: this.oid,
                                                    human_id: this.list[index].human_id,
                                                    human_name: this.list[index].human_name,
                                                    bouns_sum: this.list[index].mony1,
                                                    sale_sum: this.list[index].mony2,
                                                    deduct_sum: this.list[index].mony3,
                                                    salary_standard_sum: this.list[index].zje,
                                                    salary_paid_sum: this.list[index].sum,
                                                }
                                            })
                                                .then(res => {
                                                    console.info(res);
                                                })
                                                .catch(err => {
                                                    console.info(err);
                                                });
                                        }
                                        this.$message({
                                            type: 'success',
                                            message: '提交成功!'
                                        });
                                        this.eas();
                                    })
                                    .catch(err => {
                                        console.info(err);
                                    });
                            }).catch(() => {
                                this.$message({
                                    type: 'info',
                                    message: '已取消提交'
                                });
                            });
                        } else {
                            this.$message({
                                type: 'error',
                                message: '请填写完整信息!'
                            });
                            return false;
                        }
                    });
                },
                eas() {
                    location.href = "/salary_grant/salary_grant";
                },
                cx(row) {
                    //按薪酬编号查薪酬详细信息
                    axios.get('/salary_grant/Que', {
                        params: {
                            id: row.salary_standard_id,
                        }
                    })
                        .then(res => {
                            console.info(res);
                            this.list1 = res.data;
                        })
                        .catch(err => {
                            console.info(err);
                        });
                },
                //随机编号
                idbm() {
                    let yy = new Date().getFullYear();
                    let mm = new Date().getMonth() + 1;
                    let dd = new Date().getDate();
                    let hh = new Date().getHours();
                    let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes();
                    let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds();
                    this.oid = "KP" + yy + mm + dd + hh + mf + ss;
                },
                fill() {
                    this.idbm();
                    //用户查询
                    axios.get('/users/que', {
                    })
                        .then(res => {
                            console.info(res);
                            this.listm = res.data;
                        })
                        .catch(err => {
                            console.info(err);
                        });
                     //按三级机构查人力资源
                    axios.get('/salary_grant/FenYTo', {
                        params: {
                            third_kind_id:@ViewBag.third_kind_id,
                        }
                    })
                        .then(res => {
                            console.info(res);
                            this.list = res.data.Data;
                            for (var index in this.list) {
                                this.list[index].zje = this.list[index].salary_sum;
                            }
                        })
                        .catch(err => {
                            console.info(err);
                        });
                     //按三级机构查人力资源未发工资
                      axios.get('/salary_grant/FenYTos', {
                        params: {
                            third_kind_id:@ViewBag.third_kind_id,
                        }
                    })
                        .then(res => {
                            console.info(res);
                            this.lists = res.data.Data;
                            this.total = res.data.Row;
                            this.form.salary_standard_sum = res.data.sum;
                            this.form.salary_paid_sum = res.data.sum;
                        })
                        .catch(err => {
                            console.info(err);
                        });
                },
                get() {
                    //当前时间
                    this.form.regist_time = new Date();
                },
            },
            mounted() {
                //时间计时器
                setInterval(this.get, 1000);
            },
             //可以对vue的数据和方法进行操作,不能对DOM进行操作
            created: function () {
                this.fill();
            }
        });
    </script>
    <style scoped>
        .el-col-4 {
            width: 20%;
            font-size: 15px;
            font-weight: 900;
            line-height:0px;
        }
        .el-card__body {
            padding: 35px;
        }

        element.style {
            height: 100%;
            width: 1239px;
        }

        .el-button.is-circle {
            border-radius: 50%;
            padding: 12px;
            position: relative;
            top: -10px;
            right: -570px;
        }
        ._klpo {
            float: right;
        }
    </style>
</body>
</html>
